#include <fuss.hpp>
#include <iostream>


// Define what messages are available to be published.
struct greeting : fuss::message<>
{};

// Note that messages can have parameters.
struct echo : fuss::message<std::string>
{};

// Create a publisher object
struct noisy : fuss::shouter<greeting, echo>
{
    void greet()
    {
        // Publishes the `greeting` message.
        // `shout()` is protected, so we create a member function to call it
        shout<greeting>();
    }

    void repeat(const std::string &s)
    {
        // Publishes the `echo` message with a string as parameter
        shout<echo>(s);
    }
};

int main()
{
    // Instantiate the publisher
    noisy n;

    // Subscribe to the messages
    auto greeting_listener = n.listen<greeting>([]() { std::cout << "Hello world!" << std::endl; });

    n.listen<echo>([](std::string s) { std::cout << s << std::endl; });

    n.greet();                 // prints 'Hello world!'
    n.repeat("What a fuss!");  // prints 'What a fuss!'

    // Unsubscribe from a message
    n.unlisten(greeting_listener);

    n.greet();  // doesn't print anything
    return 0;
}